#include "EventReceiver.h"

class Boomerang;
class Cell;
class Character;
class Controller;
class File;
class Game;
class Item;
class Object;
class Player;
class Quadrant;
class Realm;
class Sword;

class Controller {
public:
	Controller(int Axes) {
		if(Axes == 4) {
			// back button set to D
			X = 0;
			A = 1;
			B = 2;
			Y = 3;
			LB = 4;
			RB = 5;
			LT = 6;
			RT = 7;
			Back = 8;
			Start = 9;
			LStickButton = 10;
			RStickButton = 11;
		} else {
			// back button set to X
			A = 0;
			B = 1;
			X = 2;
			Y = 3;
			LB = 4;
			RB = 5;
			Back = 6;
			Start = 7;
			LStickButton = 8;
			RStickButton = 9;
		}
	}
	~Controller() {}
	int A;
	int B;
	int Back;
	int LB;
	int LStickButton;
	int LT;
	int RB;
	int RStickButton;
	int RT;
	int Start;
	int X;
	int Y;
};
class File {
public:
	File(const char* FilePath);
	~File() {}
	int Copy(std::string Source_File_Path, std::string Dest_File_Path);
	int Delete(std::string File_Path);
	xml_document* GetXML();
	bool Read();
	int Rename(std::string Source_File_Path, std::string Dest_File_Path);
private:
	const char* Path;
	xml_document XML;
};
class Game {
public:
	Game();
	~Game() {}

	vector<Object*> Objects;
	Player* Link;
	void setPlayer(Player* Link_);

	IrrlichtDevice* Device;
	IVideoDriver* Driver;
	vector <rect<s32>> LinkImages;
	File* MapFile;
	EventReceiver* Receiver;
	File* SaveFile;
	s32 Scale;
	ISoundEngine* Sound;
	ITexture* SpritesLink;
	ITexture* SpritesBoomerang;
	ITexture* SpritesSword;
	vector <ISoundSource*> Sounds;
	//vector <rect<s32>> ItemImages;
	vector <rect<s32>> BoomerangWoodenImages;
	vector <rect<s32>> BoomerangMetalImages;
	rect<s32> ImageSwordWoodenEast;
	rect<s32> ImageSwordWoodenSouth;
	rect<s32> ImageSwordWoodenWest;
	rect<s32> ImageSwordWoodenNorth;
};
class Object {
public:
	Object() {}
	Object(s32 X_,s32 Y_,SColor Colour_) {
		X = X_;
		Y = Y_;
		Colour = Colour_;
		ImageRect = &Zelda->LinkImages[0];
	}
	~Object() {}
	static Game* Zelda;
	virtual void VarAct(void (*pFunction()));
	virtual void Act();
	virtual void Draw();
	//void Draw(ITexture* Texture,position2d<s32> Position,position2d<s32> RotationPoint,f32 Rotation,vector2df Scale);
	rect<s32>* GetImageRect();
	bool IsActing();
	s32 getX();
	s32 getY();
protected:
	bool Acting;
	SColor Colour;
	rect<s32>* ImageRect;
	s32 X;
	s32 Y;
};
class Realm {
public:
	Realm();
	~Realm() {}
protected:
	int ID;
	std::string Name;
	eRealmType Type;
};
class Quadrant : public Object {
public:
	Quadrant();
	~Quadrant() {}
protected:
};
class Cell : Object {
public:
	Cell();
	~Cell() {}
protected:
};
class Character : public Object {
public:
	Character() {}
	~Character() {}
	void AddItem(Item* pItem);
	virtual void Animate();
	virtual void Draw() = 0;
	eAction GetAction();
	eDirection GetDirection();
	virtual eSwordType GetSwordType() = 0;
	virtual position2d<s32> GetUseItemPosition(Item* CurrentItem) = 0;
	void ResetAction();
	virtual void SetImages() = 0;
	virtual void SetImageRects() = 0;
	void UseItem(bool ChangeImageRects);
protected:
	eAction Action;
	s32 AnimationInterval;
	eDirection Direction;
	rect<s32>* ImageRect1;
	rect<s32>* ImageRect2;
	vector <Item*> Items;
	u32 UseItemStartTime;
};
class Player : public Character {
public:
	Player(s32 CoordinateX, s32 CoordinateY, eCloakColour CloakColour_, eShieldType ShieldType_, eSwordType SwordType_);
	Player() {}
	~Player() {}
	void Act();
	void Draw();
	eSwordType GetSwordType();
	position2d<s32> GetUseItemPosition(Item* CurrentItem);
	void SetImages();
	void SetImageRects();
protected:
	eBoomerangType BoomerangType;
	eCloakColour CloakColour;
	rect<s32>* ImageLungeEast;
	rect<s32>* ImageLungeNorth;
	rect<s32>* ImageLungeSouth;
	rect<s32>* ImageLungeWest;
	rect<s32>* ImageWalkEast1;
	rect<s32>* ImageWalkEast2;
	rect<s32>* ImageWalkNorth1;
	rect<s32>* ImageWalkNorth2;
	rect<s32>* ImageWalkSouth1;
	rect<s32>* ImageWalkSouth2;
	rect<s32>* ImageWalkWest1;
	rect<s32>* ImageWalkWest2;
	eShieldType ShieldType;
	eSwordType SwordType;
};
class Item : public Object {
public:
	Item();
	~Item();
	bool getIsActive();
	ISound* getSFX();
protected:
	bool isActive;
	ISound* SFX;
};
class Boomerang : public Item {
public:
	Boomerang(Character* pCharacter);
	~Boomerang();
	void Act();
	void Draw();
protected:
	f32 AnimationInterval;
	f32 direction;
	f32 distance;
	u32 ImageIterator;
	vector <rect<s32>*> ImageRects;
	u32 LastTimeCheck;
	Character* Owner;
	position2d<s32> posCurrent;
	position2d<s32> posInitial;
	bool returning;
	f32 speed;
};
class Sword : public Item {
public:
	Sword(Character* pCharacter);
	Sword();
	~Sword();
	void Act();
	void Draw();
	void SetImageRect();
protected:
	eDirection Direction;
	Character* Owner;
	position2d<s32> posCurrent;
	position2d<s32> posInitial;
	eSwordType SwordType;
};